package com.yzt.zhuju.utils;

import java.util.HashMap;

/**
 * author : bob
 * date   : 2022/12/1
 * desc   :
 */
public class TransferCacheUtils {

    private static final HashMap<Object, Object> cache = new HashMap<>();

    public static void putTransferData(Object key, Object value) {
        if (key != null && value != null) {
            cache.put(key, value);
        }
    }

    public static Object getTransferData(Object key) {
        if (key != null && cache != null) {
            try {
                return cache.get(key);
            } catch (Exception e) {
                return null;
            }
        }
        return null;
    }

    public static Object getTransferData(Object key, Object defaultObj) {
        if (key != null && cache != null) {
            try {
                if (cache.get(key) == null) {
                    return defaultObj;
                }
                return cache.get(key);
            } catch (Exception e) {
                return defaultObj;
            }
        }
        return defaultObj;
    }

    public static Object removeTransferData(Object key) {
        if (key != null && cache != null) {
            try {
                return cache.remove(key);
            } catch (Exception e) {
                return null;
            }
        }
        return null;
    }

    public static boolean getTransferDataBool(Object key) {
        if (key != null && cache != null) {
            try {
                Object o = cache.get(key);
                if (o != null) {
                    return (boolean) cache.get(key);
                }
                return false;
            } catch (Exception e) {
                return false;
            }
        }
        return false;
    }

    public static String getTransferDataStr(Object key) {
        if (key != null && cache != null) {
            try {
                Object o = cache.get(key);
                if (o != null) {
                    return (String) cache.get(key);
                }
                return "";
            } catch (Exception e) {
                return "";
            }
        }
        return "";
    }
}

